package com.zcc.blog.controller;

import com.zcc.blog.service.BlogService;
import com.zcc.blog.service.CategoryService;
import com.zcc.blog.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zcc
 */
@Api(tags = "垃圾箱")
@RestController
@RequestMapping("/dustbin")
public class DustbinController {
    @Autowired
    CategoryService categoryService;
    @Autowired
    BlogService blogService;

    @ApiOperation("分页查找垃圾箱中的分类")
    @GetMapping("/categories")
    public Result findCategories(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer size, Long id){
        return categoryService.findCategories(currentPage, size, id, 1);
    }

    @ApiOperation("查找所有垃圾箱中的的分类")
    @GetMapping("/dustbinCategories/{id}")
    public Result getAllCategories(@PathVariable Long id){
        return categoryService.getAllCategories(id, 1);
    }

    @ApiOperation("搜索垃圾箱中的分类")
    @GetMapping("/searchDustbinCategories")
    public Result searchCategories(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer size, String name, Long id){
        return categoryService.searchCategories(name, currentPage, size, id, 1);
    }

    @ApiOperation("恢复分类")
    @RequiresAuthentication
    @PutMapping("/recoverDustbinCategory/{id}")
    public Result recoverCategory(@PathVariable Long id){
        return categoryService.recoverCategory(id);
    }

    @ApiOperation("分页查找垃圾箱中的博客")
    @GetMapping("/blogs")
    public Result findBlogs(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer size, Long id){
        return blogService.findBlogs(currentPage, size, id, 1);
    }

    @ApiOperation("条件查找垃圾箱中的博客")
    @GetMapping("/searchDustbinBlogs")
    public Result searchBlogs(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer size, String title, String description, String content, Long id){
        return blogService.searchBlogs(title, description, content, currentPage, size, id, 1);
    }

    @ApiOperation("恢复博客")
    @RequiresAuthentication
    @PutMapping("/recoverDustbinBlog/{id}")
    public Result recoverBlog(@PathVariable Long id){
        return blogService.recoverBlog(id);
    }
}
